package com.webchat.ugc.repository.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreUpdate;
import jakarta.persistence.Table;
import jakarta.persistence.Version;
import lombok.Data;

import java.util.Date;


/**
 * 朋友圈动态实体
 */
@Data
@Entity
@Table(name = "web_chat_moment")
public class MomentEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    protected Long id;

    /**
     * 动态作者
     */
    @Column(name = "author", nullable = false, length = 100)
    private String author;

    /**
     * 正文（纯文本）
     */
    @Column(name = "content", length = 300)
    private String content;

    /**
     * 状态（1-正常）
     */
    @Column(name = "status", nullable = false)
    private int status = 1;

    /**
     * 是否包含图片（true-包含）
     */
    @Column(name = "include_images")
    private boolean includeImages;

    /**
     * 是否包含视频（true-包含）
     */
    @Column(name = "include_video")
    private boolean includeVideo;

    /**
     * 是否包含链接（true-包含）
     */
    @Column(name = "include_link")
    private boolean includeLink;

    @Column(name = "ip", length = 30)
    private String ip;

    /**
     * IP归属地
     */
    @Column(name = "ip_address", length = 100)
    private String ipAddress;

    @Column(name = "review_score", length = 100)
    private Integer reviewScore;

    @Column(name = "create_date")
    private Date createDate;

    @Column(name = "update_by")
    private String updateBy;

    @Column(name = "update_date")
    private Date updateDate;

    @PreUpdate
    public void preUpdate() {
        this.updateDate = new Date();
    }

    @PrePersist
    public void prePersist() {
        Date now = new Date();
        if (this.createDate == null) {
            this.createDate = now;
        }
    }
}
